<template>
  <!-- 节点表单弹窗 -->
  <a-modal
    :title="headerTitle"
    :visible.sync="dialogVisible"
    width="900px"
    @cancel="handleCancel"
  >
    <a-spin :spinning="loading">
      <!-- 表单 -->
      <a-form-model
        ref="ruleForm"
        :model="forms"
        :rules="rules"
        :label-col="{ span: 8 }"
        :wrapper-col="{ span: 16 }"
      >
        <div id="dialogDistrictBox">
          <a-row>
            <a-col :span="24">
              <a-form-model-item
                prop="securityCheckTypeName"
                label="安全检查类型名称"
              >
                <BaseInput
                  v-model="forms.securityCheckTypeName"
                  :max-length="30"
                  :disabled="editModel == '2'"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                prop="securityRisksDescription"
                label="检查类型描述"
              >
                <baseTextarea
                  v-model="forms.securityRisksDescription"
                  :max-length="300"
                  :disabled="editModel == '2'"

                  :rows="6"
                />
              </a-form-model-item>
            </a-col>
          </a-row>
        </div>
      </a-form-model>
    </a-spin>
    <!-- 页脚操作栏 -->
    <div
      slot="footer"
      class="btn_box"
    >
      <a-button
        v-if="editModel != 2"
        :loading="loading"
        type="primary"
        class="button_right"
        @click="handleOk"
      >
        提交
      </a-button>
      <a-button
        type="primary"
        @click="handleCancel"
      >
        关闭
      </a-button>
    </div>
  </a-modal>
</template>

<script>
import { checkType } from '@/api/quality/safe' // 问题维护api

export default {
  name:'a'+ Date.now(),
  props: {
    // 显隐控件
    visible: {
      type: Boolean,
      default() {
        return false
      },
    },
    // 操作类型
    editModel: {
      type: [String, Number],
      default() {
        return 0
      },
    },
    // 表单
    form: {
      type: Object,
      default() {
        return null
      },
    },
    // 标题
    headerTitle: {
      type: String,
      default() {
        return ''
      },
    },
  },
  computed: {
    // 与父组件绑定visible
    dialogVisible: {
      get: function () {
        return this.visible
      },
      set: function (e) {
        this.$emit('update:visible', e)
      },
    },
  },
  data() {
    return {
      forms: {},
      loading: false,
      rules: {
        securityCheckTypeName: [{ required: true, whitespace:true,message: '请输入安全检查类型名称', trigger: 'change' }],
        securityRisksDescription: [{ required: true, whitespace:true,message: '请输入检查类型描述', trigger: 'change' }],
      },
    }
  },
  methods: {
    handleOk() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.loading = true
          this.$emit('conform', this.forms)
        } else {
          this.$message.warning("请填写完所有必填项信息")
          console.log('error submit!!')
          return false
        }
      })
    },
    handleCancel() {
      this.dialogVisible = false
    },
    handleChange() {},
  },
  watch: {
    visible(e) {
      if (e) {
        this.$nextTick(() => {
          if (this.editModel) {
            this.loading = true
            checkType
              .getDetail({
                id: this.form.id,
              })
              .then((res) => {
                this.loading = false
                if (res.code === 200) {
                  this.forms = res.data
                }
              })
              .catch((res) => {
                this.loading = false
              })
          }
        })
      } else {
        this.$refs.ruleForm.resetFields()
      }
    },
  },
}
</script>

<style>
#dialogDistrictBox .ant-checkbox-group .ant-form-item label {
  position: relative !important;
}
</style>
